package doublePoint;

public class QuestionThree {
    public int[] twoSum(int[] numbers, int target) {
        if (numbers.length == 0)return null;
        for (int i = 0; i < numbers.length; i++) {
            int temp = target - numbers[i];
            int search = search(i + 1, numbers.length, numbers, temp);
            if (search != -1){
                return new int[]{i,search};
            }
        }
        return null;
    }
    public int search(int left,int right,int[] nums,int target){
        while(left <= right){
            int mid = (left + right)/2;
            if (nums[mid] == target){
                return nums[mid];
            }else if(nums[mid] > target){
                left = mid+1;
            }else if(nums[mid] < target){
                right = mid-1;
            }
        }
        return -1;
    }
}
